package com.ftg.learn.chapter03;

/**
 * 青蛙
 *
 * @author 布衣
 */
public class LearnFrag {

//    while  dowhile  for  go  (将所有的循环  只保留for)


    public static int myIndexof(String str, char c, int index) {
        for (int i = index; i < str.length(); i++) {
            if (str.charAt(i) == c) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {

        String st = "fjdsakljfkldsjakfjdskl";
        int start = 0;
        int num1 = 0;
        while ((start = myIndexof(st, 'a', start)) != -1) {
            num1++;
            start++;
        }
        System.out.println("有几个A = " + num1);

//
//        int i = 1;
//        int max = 10;
//        //没有边界时   只有结束
//        while(i <= max){
//            System.out.println(i++);
//        }
//
//        //边界 开始  结束   步长
//        for(int j = 1;j <= max;j++){
//            System.out.println(j);
//        }

        int height = 7;
        int jump = 3;
        int down = 1;
        int position = 0;
        int num = 1;
        while ((position += jump) < height) {
            position -= down;
            num++;
        }
        System.out.println(num);


//        for(ex1;ex2;ex3){
//            codeblock;
//        }
//        while(exp1[boolean]){
//            codeblock;
//        }
        fragJumpWell(-7, 2, 3);
    }

    /**
     * 跳水
     *
     * @param height1 井深
     * @param jump1   跳几米
     * @param down1   下滑
     * @return 次数
     */
    public static int fragJumpWell(int height1, int jump1, int down1) {
        if (height1 <= 0) {
            //IllegalArgumentException 参数异常
            throw new IllegalArgumentException("井深height1不能为负数");
        }
        if(jump1 <= 0){
            throw new IllegalArgumentException("井深jump1不能为负数");
        }
        if(down1 <= 0){
            throw new IllegalArgumentException("井深down1不能为负数");
        }
        if(down1 >= jump1){
            throw new IllegalArgumentException("井深down1不能大于jump1");
        }
        int position1 = 0;
        int num2 = 0;
        do {
            if (num2 != 0) {
                position1 -= down1;
            }
            position1 += jump1;
            num2++;
        } while (position1 < height1);
        return num2;
    }

}
